const Koa = require('koa');
const compose = require('koa-compose');
const koajwt = require('koa-jwt');
const alias = require('module-alias/register') // 启用@别名
// var module = require('@deep/module')

const MD = require('./middlewares/');
// const config = require('./config')
const config = require('./config')
const utils = require('./common/utils.js')
const service = require('./service')

const app = new Koa();


const host = process.env.SERVER_HOST
const port = process.env.SERVER_PORT

app.context.config = config;
app.context.utils = utils;
app.context.service = service;

app.use(compose(MD));

app.on('error', (err, ctx) => {
	if (ctx) {
		ctx.body = {
			code: 9999,
			message: `程序错误：${err.message}`
		};
	}
});

app.listen(port, host, () => {
	// console.log(process.env.DB_PASSWORD);
	console.log(`API server listening on ${host}:${port}`);
});
